#include "Gencpp_Individual.h"

Gencpp_Individual::Gencpp_Individual(void)
{
	mi_SizeGenotype = SIZE_GENOTYPE;
	ma_Genotype = new int[mi_SizeGenotype];
	mf_Red = 0.f;
	mf_Green = 0.f;
	mf_Blue = 0.f;
	mf_Fitness = 0.f;
}

Gencpp_Individual::~Gencpp_Individual(void)
{
}

float Gencpp_Individual::getFitness()
{
	return mf_Fitness;
}

void Gencpp_Individual::setFitness(float _fFitness)
{
	mf_Fitness = _fFitness;
}

void Gencpp_Individual::createRandomGenotype(void)
{
	for( int i=0;i<mi_SizeGenotype;i++)
	{
		srand( time(NULL) );
		if(rand() < RAND_MAX/2)
			ma_Genotype[i] = 1;
		else
			ma_Genotype[i] = 0;
	}
}

void Gencpp_Individual::computeColor(void)
{
	for (int i=0;i<8;i++)
		mf_Red = mf_Red + ma_Genotype[i]*pow((double)2,i);
	for (int i=0;i<8;i++)
		mf_Green = mf_Green + ma_Genotype[8+i]*pow((double)2,i);
	for (int i=0;i<8;i++)
		mf_Blue = mf_Blue + ma_Genotype[16+i]*pow((double)2,i);
}
